<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>My Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="This is my first blog.">
<meta property="og:type" content="website">
<meta property="og:title" content="My Blog">
<meta property="og:url" content="http://yoursite.com/page/7/index.html">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="This is my first blog.">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Alanisia">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="My Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.ico">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">My Blog</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">我的博客 -- 记录编程过程中所遇到的问题与总结</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-go" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/go/" class="article-date">
  <time datetime="2020-06-01T11:32:16.000Z" itemprop="datePublished">2020-06-01</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/go/">Golang</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Golang由Google公司在2009年发布。</p>
<h2 id="下载和安装"><a href="#下载和安装" class="headerlink" title="下载和安装"></a>下载和安装</h2><p>去官网下载对应系统的压缩包， 解压后即安装成功。</p>
<ul>
<li><p>设置<code>GOROOT</code>，<code>GOPATH</code></p>
<ul>
<li><p>Linux: 打开.profile/.bash_profile文件，在文件末尾写入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">export PATH=$PATH:/usr/local/lib/go/bin</span><br><span class="line">export GOROOT=/usr/local/lib/go</span><br><span class="line">export GOPATH=/home/alanisia/go</span><br></pre></td></tr></table></figure>

<p>执行命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">source</span> ~/.profile <span class="comment"># or bash_profile</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ul>
<h2 id="添加中国代理"><a href="#添加中国代理" class="headerlink" title="添加中国代理"></a>添加中国代理</h2><p>Go 1.13以上(推荐)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go env -w GO111MODULE=on</span><br><span class="line">go env -w GOPROXY=https://goproxy.cn,direct</span><br></pre></td></tr></table></figure>

<p>macOS or Linux</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> GO111MODULE=on</span><br><span class="line"><span class="built_in">export</span> GOPROXY=https://goproxy.cn</span><br></pre></td></tr></table></figure>

<p>或者</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">"export GO111MODULE=on"</span> &gt;&gt; ~/.profile</span><br><span class="line"><span class="built_in">echo</span> <span class="string">"export GOPROXY=https://goproxy.cn"</span> &gt;&gt; ~/.profile</span><br><span class="line"><span class="built_in">source</span> ~/.profile</span><br></pre></td></tr></table></figure>

<p>Windows</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$env</span>:GO111MODULE = <span class="string">"on"</span></span><br><span class="line"><span class="variable">$env</span>:GOPROXY = <span class="string">"https://goproxy.cn"</span></span><br></pre></td></tr></table></figure>

<h2 id="下载模块"><a href="#下载模块" class="headerlink" title="下载模块"></a>下载模块</h2><p>传统下载模块的方式：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get &lt;module&gt;</span><br></pre></td></tr></table></figure>

<p>如下载gopls：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get golang.org/x/tools/gopls</span><br></pre></td></tr></table></figure>

<p>这将把模块下载到<code>$GOPATH/pkg</code>路径下。</p>
<p>以这种方式进行包管理，项目目录必须在<code>$GOPATH</code>路径下。1.12版本以后增加了go mod包管理的新形式，项目目录可以不用在<code>$GOPATH</code>以下了。</p>
<p>另外开一个空文件夹，在该文件夹下运行以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go mod init &lt;module_name&gt;</span><br></pre></td></tr></table></figure>

<p>可以在根目录生成一个go.mod文件，所有的项目依赖均写在该文件内。如果在任意源文件添加某个第三方模块，go.mod会自动地从<code>$GOPATH/pkg</code>寻找模块，找不到的话会自动下载。</p>
<h2 id="编译与运行"><a href="#编译与运行" class="headerlink" title="编译与运行"></a>编译与运行</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">go build main.go <span class="comment"># 编译</span></span><br><span class="line">./main <span class="comment"># 运行</span></span><br><span class="line">go run main.go <span class="comment"># 编译并运行</span></span><br></pre></td></tr></table></figure>

<p>根目录下在没有标有<code>package main</code>这行代码的go源文件时，运行<code>go build</code>并不会生成可执行二进制文件。</p>
<p><code>go build</code>会自动从头编译整个项目。</p>
<h2 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h2><p>参考文档<a href="https://golang.google.cn/doc/" target="_blank" rel="noopener">https://golang.google.cn/doc/</a>。</p>
<h2 id="标准库API"><a href="#标准库API" class="headerlink" title="标准库API"></a>标准库API</h2><p>参考文档<a href="https://go-zh.org/pkg" target="_blank" rel="noopener">https://go-zh.org/pkg</a>。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/go/" data-id="ckpb8zvjn000ldsvlabit53sf" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/go/" rel="tag">go</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-multi-module-pom" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/multi-module-pom/" class="article-date">
  <time datetime="2020-05-15T15:59:48.000Z" itemprop="datePublished">2020-05-15</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/multi-module-pom/">Maven多模块编程</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="父pom"><a href="#父pom" class="headerlink" title="父pom"></a>父pom</h2><p>父pom是自模块pom的父节点，应在父pom里标注modules：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">modules</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 子模块 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">module</span>&gt;</span><span class="tag">&lt;/<span class="name">module</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">modules</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>父pom写在dependencyManagement里的依赖只是起到统一管理版本的作用，子模块若需要标注在该标签的依赖须在子模块中再次导入，但不必再写版本：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- parent pom --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 依赖 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.xxx<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>xxx<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- module pom --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 依赖 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.xxx<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>xxx<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="子pom"><a href="#子pom" class="headerlink" title="子pom"></a>子pom</h2><p>子pom需要标注继承的父pom：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.xxx<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>xxx<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">relativePath</span>&gt;</span><span class="comment">&lt;!-- 父pom的相对路径 --&gt;</span><span class="tag">&lt;/<span class="name">relativePath</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">packaging</span>&gt;</span>pom<span class="tag">&lt;/<span class="name">packaging</span>&gt;</span><span class="comment">&lt;!-- 父模块应以pom方式打包 --&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="Spring-Boot多模块项目"><a href="#Spring-Boot多模块项目" class="headerlink" title="Spring Boot多模块项目"></a>Spring Boot多模块项目</h2><p>子pom需要标注继承的父pom为spring-boot-starter-parent：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.2.7.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">relativePath</span>&gt;</span><span class="comment">&lt;!-- 父pom的相对路径 --&gt;</span><span class="tag">&lt;/<span class="name">relativePath</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">packaging</span>&gt;</span>pom<span class="tag">&lt;/<span class="name">packaging</span>&gt;</span><span class="comment">&lt;!-- 父模块应以pom方式打包 --&gt;</span></span><br></pre></td></tr></table></figure>

<p>此后引入spring-boot-starter相关包时不必再写版本。</p>
<p>不必在父pom中写build节点，运行项目的插件写在子模块的pom.xml里，不写在父pom中。</p>
<h2 id="Spring-Boot多模块项目打包"><a href="#Spring-Boot多模块项目打包" class="headerlink" title="Spring Boot多模块项目打包"></a>Spring Boot多模块项目打包</h2><p>进入需要打包的模块，在pom.xml中设置打包插件：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">resources</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">resource</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">directory</span>&gt;</span>src/main/resources<span class="tag">&lt;/<span class="name">directory</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">includes</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">include</span>&gt;</span>**.*<span class="tag">&lt;/<span class="name">include</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">include</span>&gt;</span>**/*.*<span class="tag">&lt;/<span class="name">include</span>&gt;</span><span class="comment">&lt;!-- i18n能读取到 --&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">include</span>&gt;</span>**/*/*.*<span class="tag">&lt;/<span class="name">include</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">includes</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">resource</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resources</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">finalName</span>&gt;</span>app<span class="tag">&lt;/<span class="name">finalName</span>&gt;</span><span class="comment">&lt;!-- 为jar包取名 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 热部署 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--fork :  如果没有该项配置，这个devtools不会起作用，即应用不会restart --&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">fork</span>&gt;</span>true<span class="tag">&lt;/<span class="name">fork</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">mainClass</span>&gt;</span><span class="comment">&lt;!-- 启动类全限定名 --&gt;</span><span class="tag">&lt;/<span class="name">mainClass</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">layout</span>&gt;</span>ZIP<span class="tag">&lt;/<span class="name">layout</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">executions</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">execution</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">goals</span>&gt;</span></span><br><span class="line">                    	<span class="tag">&lt;<span class="name">goal</span>&gt;</span>repackage<span class="tag">&lt;/<span class="name">goal</span>&gt;</span><span class="comment">&lt;!--可以把依赖的包都打包到生成的Jar包中--&gt;</span></span><br><span class="line">                    <span class="tag">&lt;/<span class="name">goals</span>&gt;</span></span><br><span class="line">                    <span class="comment">&lt;!--可以生成不含依赖包的不可执行Jar包--&gt;</span></span><br><span class="line">                    <span class="comment">&lt;!-- configuration&gt;</span></span><br><span class="line"><span class="comment">                    &lt;classifier&gt;exec&lt;/classifier&gt;</span></span><br><span class="line"><span class="comment">                    &lt;/configuration&gt; --&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">execution</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">executions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-surefire-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.19.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">skipTests</span>&gt;</span>true<span class="tag">&lt;/<span class="name">skipTests</span>&gt;</span>    <span class="comment">&lt;!--默认关掉单元测试 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>运行命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mvn clean package -Dmaven.test.skip=<span class="literal">true</span> <span class="comment"># 跳过测试（若已经在pom.xml配置好则不需要)</span></span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/multi-module-pom/" data-id="ckpb8zvkd001udsvl6rsf9is7" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/" rel="tag">java</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-aspectj" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/aspectj/" class="article-date">
  <time datetime="2020-05-15T15:59:20.000Z" itemprop="datePublished">2020-05-15</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/aspectj/">Aspectj切面编程</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>首先导入依赖：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.aspectj<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>aspectjrt<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>1.9.5<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.aspectj<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>aspectjweaver<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>1.9.5<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>在切面类添加注解<code>@Aspect</code>，添加该注解的类将被声明为切面类。</p>
<p>若与SpringBoot集成，应添加注解<code>@Component</code>使Spring能够扫描到该切面类。</p>
<h2 id="切点"><a href="#切点" class="headerlink" title="切点"></a>切点</h2><p>使用<code>@Pointcut</code>定义切点。</p>
<p>可声明一个方法，并添加<code>@Pointcut</code>注解，该方法将成为切点。</p>
<p><code>@Pointcut</code>的value参数的值：</p>
<ul>
<li><p><code>execution</code>：值是一个方法，运行到该方法时将被切入</p>
<p>支持通配符，</p>
<ol>
<li>*：匹配一个或多个字符</li>
<li>..：匹配子包或方法参数 </li>
</ol>
<p>如：<code>execution(* com.xxx.xxx..Xxx.*(..))</code>表示在运行到所有com.xxx.xxx的所有子包的Xxx类的所有方法时被切入</p>
</li>
<li><p><code>within</code>：值是一个类，支持通配符</p>
</li>
<li><p><code>args</code>：方法参数的类名</p>
</li>
<li><p><code>@args</code>：注解类的类名</p>
</li>
<li><p><code>@within</code>：值是一个注解，标有该注解的类运行时将被切入</p>
</li>
<li><p><code>@target</code>：同@within</p>
</li>
<li><p><code>@annotation</code>：值是一个注解，标有该注解的方法运行时将被切入</p>
<p>可以用&amp;&amp;，||，! 对value中的语句进行任意组合。</p>
</li>
</ul>
<h2 id="注解"><a href="#注解" class="headerlink" title="注解"></a>注解</h2><ul>
<li><code>@Before</code>：切点代码执行前先执行的方法</li>
<li><code>@After</code>：方法返回结果后再执行的方法</li>
<li><code>@Around</code>：切点代码执行前后都执行的方法</li>
<li><code>@AfterReturning</code>：运行在方法返回一个结果后，在拦截器返回结果    </li>
<li><code>@AfterThrowing</code>：在抛出异常后运行方法</li>
</ul>
<p>以上注解都可以具有pointcut参数，可自定义切点。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/aspectj/" data-id="ckpb8zvjb0003dsvlgs195jxm" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java/" rel="tag">java</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-vim-coc" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/vim-coc/" class="article-date">
  <time datetime="2020-05-13T16:23:47.000Z" itemprop="datePublished">2020-05-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/vim-coc/">vim代码补全插件——coc.nvim</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>GitHub地址：<a href="https://github.com/neoclide/coc.nvim" target="_blank" rel="noopener">https://github.com/neoclide/coc.nvim</a></p>
<h2 id="安装vim-plug"><a href="#安装vim-plug" class="headerlink" title="安装vim-plug"></a>安装vim-plug</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -fLo ~/.vim/<span class="built_in">autoload</span>/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim</span><br></pre></td></tr></table></figure>

<p>neovim用户：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -fLo ~/.config/nvim/<span class="built_in">autoload</span>/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim</span><br></pre></td></tr></table></figure>

<h2 id="安装coc-nvim"><a href="#安装coc-nvim" class="headerlink" title="安装coc.nvim"></a>安装coc.nvim</h2><p>在~/.vimrc文件内添加以下代码：</p>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">call</span> plug#begin(~/.vim/autoload/plug.vim)</span><br><span class="line">Plug <span class="comment">'neoclide/coc.nvim',&#123;'branch': 'release'&#125;</span></span><br><span class="line"><span class="keyword">call</span> plug#<span class="keyword">end</span></span><br></pre></td></tr></table></figure>

<p>随后在vim执行:PlugInstall命令即可安装。</p>
<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><p>可以将以下代码复制到.vimrc文件：</p>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">" TextEdit might fail if hidden is not set.</span></span><br><span class="line"><span class="string">set hidden</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Some servers have issues <span class="keyword">with</span> backup files, see #<span class="number">649.</span></span><br><span class="line"><span class="keyword">set</span> nobackup</span><br><span class="line"><span class="keyword">set</span> nowritebackup</span><br><span class="line"></span><br><span class="line"><span class="string">" Give more space for displaying messages.</span></span><br><span class="line"><span class="string">set cmdheight=2</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Having longer updatetime (<span class="keyword">default</span> <span class="keyword">is</span> <span class="number">4000</span> ms = <span class="number">4</span> s) leads <span class="keyword">to</span> noticeable</span><br><span class="line"><span class="string">" delays and poor user experience.</span></span><br><span class="line"><span class="string">set updatetime=300</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Don<span class="comment">'t pass messages to |ins-completion-menu|.</span></span><br><span class="line"><span class="keyword">set</span> shortmess+=c</span><br><span class="line"></span><br><span class="line"><span class="string">" Always show the signcolumn, otherwise it would shift the text each time</span></span><br><span class="line"><span class="string">"</span> diagnostics appear/become resolved.</span><br><span class="line"><span class="keyword">set</span> signcolumn=yes</span><br><span class="line"></span><br><span class="line"><span class="string">" Use tab for trigger completion with characters ahead and navigate.</span></span><br><span class="line"><span class="string">"</span> NOTE: Use command <span class="comment">':verbose imap &lt;tab&gt;' to make sure tab is not mapped by</span></span><br><span class="line"><span class="string">" other plugin before putting this into your config.</span></span><br><span class="line"><span class="string">inoremap &lt;silent&gt;&lt;expr&gt; &lt;TAB&gt;</span></span><br><span class="line"><span class="string">      \ pumvisible() ? "</span>\&lt;C-n&gt;<span class="string">" :</span></span><br><span class="line"><span class="string">      \ &lt;SID&gt;check_back_space() ? "</span>\&lt;TAB&gt;<span class="string">" :</span></span><br><span class="line"><span class="string">      \ coc#refresh()</span></span><br><span class="line"><span class="string">inoremap &lt;expr&gt;&lt;S-TAB&gt; pumvisible() ? "</span>\&lt;C-p&gt;<span class="string">" : "</span>\&lt;C-h&gt;<span class="string">"</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">function! s:check_back_space() abort</span></span><br><span class="line"><span class="string">  let col = col('.') - 1</span></span><br><span class="line"><span class="string">  return !col || getline('.')[col - 1]  =~# '\s'</span></span><br><span class="line"><span class="string">endfunction</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Use &lt;c-<span class="built_in">space</span>&gt; <span class="keyword">to</span> trigger completion.</span><br><span class="line">inoremap &lt;silent&gt;&lt;expr&gt; &lt;c-<span class="built_in">space</span>&gt; coc#refresh()</span><br><span class="line"></span><br><span class="line"><span class="string">" Use &lt;cr&gt; to confirm completion, `&lt;C-g&gt;u` means break undo chain at current</span></span><br><span class="line"><span class="string">"</span> position. Coc only does snippet <span class="keyword">and</span> additional edit <span class="keyword">on</span> confirm.</span><br><span class="line"><span class="string">" &lt;cr&gt; could be remapped by other vim plugin, try `:verbose imap &lt;CR&gt;`.</span></span><br><span class="line"><span class="string">if exists('*complete_info')</span></span><br><span class="line"><span class="string">  inoremap &lt;expr&gt; &lt;cr&gt; complete_info()["</span>selected<span class="string">"] != "</span><span class="number">-1</span><span class="string">" ? "</span>\&lt;C-y&gt;<span class="string">" : "</span>\&lt;C-g&gt;u\&lt;CR&gt;<span class="string">"</span></span><br><span class="line"><span class="string">else</span></span><br><span class="line"><span class="string">  inoremap &lt;expr&gt; &lt;cr&gt; pumvisible() ? "</span>\&lt;C-y&gt;<span class="string">" : "</span>\&lt;C-g&gt;u\&lt;CR&gt;<span class="string">"</span></span><br><span class="line"><span class="string">endif</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Use `[g` <span class="keyword">and</span> `]g` <span class="keyword">to</span> navigate diagnostics</span><br><span class="line">nmap &lt;silent&gt; [g &lt;Plug&gt;(coc-diagnostic-prev)</span><br><span class="line">nmap &lt;silent&gt; ]g &lt;Plug&gt;(coc-diagnostic-<span class="keyword">next</span>)</span><br><span class="line"></span><br><span class="line"><span class="string">" GoTo code navigation.</span></span><br><span class="line"><span class="string">nmap &lt;silent&gt; gd &lt;Plug&gt;(coc-definition)</span></span><br><span class="line"><span class="string">nmap &lt;silent&gt; gy &lt;Plug&gt;(coc-type-definition)</span></span><br><span class="line"><span class="string">nmap &lt;silent&gt; gi &lt;Plug&gt;(coc-implementation)</span></span><br><span class="line"><span class="string">nmap &lt;silent&gt; gr &lt;Plug&gt;(coc-references)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Use K <span class="keyword">to</span> show documentation <span class="keyword">in</span> preview window.</span><br><span class="line">nnoremap &lt;silent&gt; K :<span class="keyword">call</span> &lt;SID&gt;show_documentation()&lt;CR&gt;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span>! s:show_documentation()</span><br><span class="line">  <span class="keyword">if</span> (index([<span class="comment">'vim','help'], &amp;filetype) &gt;= 0)</span></span><br><span class="line">    <span class="keyword">execute</span> <span class="comment">'h '.expand('&lt;cword&gt;')</span></span><br><span class="line">  <span class="keyword">else</span></span><br><span class="line">    <span class="keyword">call</span> CocAction(<span class="comment">'doHover')</span></span><br><span class="line">  endif</span><br><span class="line">endfunction</span><br><span class="line"></span><br><span class="line"><span class="string">" Highlight the symbol and its references when holding the cursor.</span></span><br><span class="line"><span class="string">autocmd CursorHold * silent call CocActionAsync('highlight')</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Symbol renaming.</span><br><span class="line">nmap &lt;leader&gt;rn &lt;Plug&gt;(coc-rename)</span><br><span class="line"></span><br><span class="line"><span class="string">" Formatting selected code.</span></span><br><span class="line"><span class="string">xmap &lt;leader&gt;f  &lt;Plug&gt;(coc-format-selected)</span></span><br><span class="line"><span class="string">nmap &lt;leader&gt;f  &lt;Plug&gt;(coc-format-selected)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">augroup mygroup</span></span><br><span class="line"><span class="string">  autocmd!</span></span><br><span class="line"><span class="string">  "</span> Setup formatexpr specified filetype(s).</span><br><span class="line">  autocmd FileType typescript,json setl formatexpr=CocAction(<span class="comment">'formatSelected')</span></span><br><span class="line">  <span class="string">" Update signature help on jump placeholder.</span></span><br><span class="line"><span class="string">  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')</span></span><br><span class="line"><span class="string">augroup end</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Applying codeAction <span class="keyword">to</span> the selected region.</span><br><span class="line"><span class="string">" Example: `&lt;leader&gt;aap` for current paragraph</span></span><br><span class="line"><span class="string">xmap &lt;leader&gt;a  &lt;Plug&gt;(coc-codeaction-selected)</span></span><br><span class="line"><span class="string">nmap &lt;leader&gt;a  &lt;Plug&gt;(coc-codeaction-selected)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Remap keys <span class="keyword">for</span> applying codeAction <span class="keyword">to</span> the current line.</span><br><span class="line">nmap &lt;leader&gt;ac  &lt;Plug&gt;(coc-codeaction)</span><br><span class="line"><span class="string">" Apply AutoFix to problem on the current line.</span></span><br><span class="line"><span class="string">nmap &lt;leader&gt;qf  &lt;Plug&gt;(coc-fix-current)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Map <span class="keyword">function</span> <span class="keyword">and</span> <span class="keyword">class</span> text objects</span><br><span class="line"><span class="string">" NOTE: Requires 'textDocument.documentSymbol' support from the language server.</span></span><br><span class="line"><span class="string">xmap if &lt;Plug&gt;(coc-funcobj-i)</span></span><br><span class="line"><span class="string">omap if &lt;Plug&gt;(coc-funcobj-i)</span></span><br><span class="line"><span class="string">xmap af &lt;Plug&gt;(coc-funcobj-a)</span></span><br><span class="line"><span class="string">omap af &lt;Plug&gt;(coc-funcobj-a)</span></span><br><span class="line"><span class="string">xmap ic &lt;Plug&gt;(coc-classobj-i)</span></span><br><span class="line"><span class="string">omap ic &lt;Plug&gt;(coc-classobj-i)</span></span><br><span class="line"><span class="string">xmap ac &lt;Plug&gt;(coc-classobj-a)</span></span><br><span class="line"><span class="string">omap ac &lt;Plug&gt;(coc-classobj-a)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Use CTRL-S <span class="keyword">for</span> selections ranges.</span><br><span class="line"><span class="string">" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver</span></span><br><span class="line"><span class="string">nmap &lt;silent&gt; &lt;C-s&gt; &lt;Plug&gt;(coc-range-select)</span></span><br><span class="line"><span class="string">xmap &lt;silent&gt; &lt;C-s&gt; &lt;Plug&gt;(coc-range-select)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Add `:Format` command <span class="keyword">to</span> format current buffer.</span><br><span class="line">command! -nargs=<span class="number">0</span> Format :<span class="keyword">call</span> CocAction(<span class="comment">'format')</span></span><br><span class="line"></span><br><span class="line"><span class="string">" Add `:Fold` command to fold current buffer.</span></span><br><span class="line"><span class="string">command! -nargs=? Fold :call     CocAction('fold', &lt;f-args&gt;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Add `:<span class="keyword">OR</span>` command <span class="keyword">for</span> organize imports of the current buffer.</span><br><span class="line">command! -nargs=<span class="number">0</span> <span class="keyword">OR</span>   :<span class="keyword">call</span>     CocAction(<span class="comment">'runCommand', 'editor.action.organizeImport')</span></span><br><span class="line"></span><br><span class="line"><span class="string">" Add (Neo)Vim's native statusline support.</span></span><br><span class="line"><span class="string">"</span> NOTE: Please see `:h coc-status` <span class="keyword">for</span> integrations <span class="keyword">with</span> external plugins that</span><br><span class="line"><span class="string">" provide custom statusline: lightline.vim, vim-airline.</span></span><br><span class="line"><span class="string">set statusline^=%&#123;coc#status()&#125;%&#123;get(b:,'coc_current_function','')&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> Mappings using CoCList:</span><br><span class="line"><span class="string">" Show all diagnostics.</span></span><br><span class="line"><span class="string">nnoremap &lt;silent&gt; &lt;space&gt;a  :&lt;C-u&gt;CocList diagnostics&lt;cr&gt;</span></span><br><span class="line"><span class="string">"</span> Manage extensions.</span><br><span class="line">nnoremap &lt;silent&gt; &lt;<span class="built_in">space</span>&gt;e  :&lt;C-u&gt;CocList extensions&lt;cr&gt;</span><br><span class="line"><span class="string">" Show commands.</span></span><br><span class="line"><span class="string">nnoremap &lt;silent&gt; &lt;space&gt;c  :&lt;C-u&gt;CocList commands&lt;cr&gt;</span></span><br><span class="line"><span class="string">"</span> Find symbol of current document.</span><br><span class="line">nnoremap &lt;silent&gt; &lt;<span class="built_in">space</span>&gt;o  :&lt;C-u&gt;CocList outline&lt;cr&gt;</span><br><span class="line"><span class="string">" Search workspace symbols.</span></span><br><span class="line"><span class="string">nnoremap &lt;silent&gt; &lt;space&gt;s  :&lt;C-u&gt;CocList -I symbols&lt;cr&gt;</span></span><br><span class="line"><span class="string">"</span> <span class="keyword">Do</span> <span class="keyword">default</span> action <span class="keyword">for</span> <span class="keyword">next</span> item.</span><br><span class="line">nnoremap &lt;silent&gt; &lt;<span class="built_in">space</span>&gt;j  :&lt;C-u&gt;CocNext&lt;CR&gt;</span><br><span class="line"><span class="string">" Do default action for previous item.</span></span><br><span class="line"><span class="string">nnoremap &lt;silent&gt; &lt;space&gt;k  :&lt;C-u&gt;CocPrev&lt;CR&gt;</span></span><br><span class="line"><span class="string">"</span> <span class="keyword">Resume</span> latest coc list.</span><br><span class="line">nnoremap &lt;silent&gt; &lt;<span class="built_in">space</span>&gt;p  :&lt;C-u&gt;CocListResume&lt;CR&gt;</span><br></pre></td></tr></table></figure>

<h2 id="语言补全服务器的安装"><a href="#语言补全服务器的安装" class="headerlink" title="语言补全服务器的安装"></a>语言补全服务器的安装</h2><p>在vim下执行:CocInstall coc-xxx，</p>
<ul>
<li>如要安装javascript/typescript的自动代码补全服务器，则执行</li>
</ul>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-tsserver</span><br></pre></td></tr></table></figure>

<ul>
<li>如要安装java的自动代码补全服务器，则执行</li>
</ul>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-java</span><br></pre></td></tr></table></figure>

<ul>
<li>如要安装go的自动代码补全服务器，则执行</li>
</ul>
<figure class="highlight vbs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-go</span><br></pre></td></tr></table></figure>

<p>确保已经安装了go官方代码补全服务器gopls，该插件基于此运行，若没有安装gopls插件会因无法下载相关的依赖而报错，进而无法提供补全。</p>
<p>根据安装的插件，<code>:CocConfig</code>命令打开配置文件，在里面写明使用的language-server</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//gopls</span></span><br><span class="line">"languageserver": &#123;</span><br><span class="line">    "golang": &#123;</span><br><span class="line">      "command": "gopls",</span><br><span class="line">      "rootPatterns": ["go.mod"],</span><br><span class="line">      "disableWorkspaceFolders": true,</span><br><span class="line">      "filetypes": ["go"]</span><br><span class="line">        <span class="comment">//If want more debug，add "args": ["serve", "-debug", "0.0.0.0:8484", "-rpc.trace"], below command.</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="comment">//go-langserver</span></span><br><span class="line">"languageserver": &#123;</span><br><span class="line">    "golang": &#123;</span><br><span class="line">      "command": "go-langserver",</span><br><span class="line">      "filetypes": ["go"],</span><br><span class="line">      "initializationOptions": &#123;</span><br><span class="line">        "gocodeCompletionEnabled": true,</span><br><span class="line">        "diagnosticsEnabled": true,</span><br><span class="line">        "lintTool": "golint"</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>如要安装c/c++的自动代码补全服务器，则执行</li>
</ul>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-clangd</span><br></pre></td></tr></table></figure>

<p>在安装该插件前应先安装clangd。</p>
<p>或者</p>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-ccls</span><br></pre></td></tr></table></figure>

<p>在安装该插件前应先安装ccls。</p>
<p>或者</p>
<figure class="highlight vbscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:CocInstall coc-cquery</span><br></pre></td></tr></table></figure>

<p>在安装该插件前应先安装cquery。</p>
<p>根据安装的插件，<code>:CocConfig</code>命令打开配置文件，在里面写明使用的language-server：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//clangd</span></span><br><span class="line">"languageserver": &#123;</span><br><span class="line">    "clangd": &#123;</span><br><span class="line">      "command": "clangd",</span><br><span class="line">      "rootPatterns": ["compile_flags.txt", "compile_commands.json"],</span><br><span class="line">      "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp"]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="comment">//ccls</span></span><br><span class="line"> "languageserver": &#123;</span><br><span class="line">    "ccls": &#123;</span><br><span class="line">      "command": "ccls",</span><br><span class="line">      "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp"],</span><br><span class="line">      "rootPatterns": [".ccls", "compile_commands.json", ".git/", ".hg/"],</span><br><span class="line">      "initializationOptions": &#123;</span><br><span class="line">         "cache": &#123;</span><br><span class="line">           "directory": "/tmp/ccls"</span><br><span class="line">         &#125;</span><br><span class="line">       &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="comment">//clang &lt; 8 on mac os x</span></span><br><span class="line">"initializationOptions": &#123;</span><br><span class="line">   "cache": &#123;</span><br><span class="line">      "directory": "/tmp/ccls"</span><br><span class="line">   &#125;,</span><br><span class="line">   "clang": &#123;</span><br><span class="line">      <span class="comment">// make sure you have installed commandLineTools</span></span><br><span class="line">      "resourceDir": "/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0",</span><br><span class="line">      "extraArgs": ["-isystem","/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",</span><br><span class="line">        "-I",  "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/"        </span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line"><span class="comment">//cquery</span></span><br><span class="line">"languageserver": &#123;</span><br><span class="line">    "cquery": &#123;</span><br><span class="line">      "command": "cquery",</span><br><span class="line">      "args": ["--log-file=/tmp/cq.log"],</span><br><span class="line">      "filetypes": ["c", "cc", "cpp", "c++"],</span><br><span class="line">      "rootPatterns": ["compile_flags.txt", "compile_commands.json", ".git/", ".hg/"],</span><br><span class="line">      "initializationOptions": &#123;</span><br><span class="line">        "cacheDirectory": "/tmp/cquery"</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/vim-coc/" data-id="ckpb8zvm6004fdsvl2g2p28va" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vim/" rel="tag">vim</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-mybatis-generator" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/mybatis-generator/" class="article-date">
  <time datetime="2020-05-13T16:07:54.000Z" itemprop="datePublished">2020-05-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/mybatis-generator/">mybatis-generator代码生成器</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>mybatis-generator是mybatis框架配套的一款代码自动生成器，提供实体类(model)、dao、mapper(xml)代码的生成。</p>
<p>使用前在pom.xml导入：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mybatis.generator<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-generator-core<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>1.3.7<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 以下依赖导入会使mybatis和ibatis冲突，导致项目报错，但不导入却会使生成的代码缺包，除非不使相关代码生成 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.ibatis<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>ibatis-core<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>mysql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mysql-connector-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>8.0.15<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>插件配置：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mybatis.generator<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-generator-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">version</span>&gt;</span>1.3.7<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">configurationFile</span>&gt;</span>src/main/resources/mybatis-generator.xml<span class="tag">&lt;/<span class="name">configurationFile</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">verbose</span>&gt;</span>true<span class="tag">&lt;/<span class="name">verbose</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">overwrite</span>&gt;</span>true<span class="tag">&lt;/<span class="name">overwrite</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">executions</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;<span class="name">execution</span>&gt;</span></span><br><span class="line">						<span class="tag">&lt;<span class="name">id</span>&gt;</span>Generate MyBatis Artifacts<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">						<span class="tag">&lt;<span class="name">goals</span>&gt;</span></span><br><span class="line">							<span class="tag">&lt;<span class="name">goal</span>&gt;</span>generate<span class="tag">&lt;/<span class="name">goal</span>&gt;</span></span><br><span class="line">						<span class="tag">&lt;/<span class="name">goals</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;/<span class="name">execution</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;/<span class="name">executions</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mybatis.generator<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-generator-core<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;<span class="name">version</span>&gt;</span>1.3.7<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>mybatis-generator.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">generatorConfiguration</span></span></span><br><span class="line"><span class="meta">        <span class="meta-keyword">PUBLIC</span> <span class="meta-string">"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"</span></span></span><br><span class="line"><span class="meta">        <span class="meta-string">"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">generatorConfiguration</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">classPathEntry</span> <span class="attr">location</span>=<span class="string">"/home/alanisia/.m2/repository/mysql/mysql-connector-java/8.0.15/mysql-connector-java-8.0.15.jar"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">context</span> <span class="attr">id</span>=<span class="string">"context"</span> <span class="attr">targetRuntime</span>=<span class="string">"MyBatis3"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"beginningDelimiter"</span> <span class="attr">value</span>=<span class="string">"`"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"endingDelimiter"</span> <span class="attr">value</span>=<span class="string">"`"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"javaFileEncoding"</span> <span class="attr">value</span>=<span class="string">"UTF-8"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 为模型生成序列化方法--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">type</span>=<span class="string">"org.mybatis.generator.plugins.SerializablePlugin"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 为生成的Java模型创建一个toString方法 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">type</span>=<span class="string">"org.mybatis.generator.plugins.ToStringPlugin"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">commentGenerator</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"suppressDate"</span> <span class="attr">value</span>=<span class="string">"true"</span> /&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"suppressAllComments"</span> <span class="attr">value</span>=<span class="string">"true"</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">commentGenerator</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 数据库链接地址账号密码 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">jdbcConnection</span> <span class="attr">driverClass</span>=<span class="string">"com.mysql.cj.jdbc.Driver"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">connectionURL</span>=<span class="string">"jdbc:mysql://localhost:3306/music_site?serverTimezone=UTC"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">userId</span>=<span class="string">"root"</span> <span class="attr">password</span>=<span class="string">"063833"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"nullCatalogMeansCurrent"</span> <span class="attr">value</span>=<span class="string">"true"</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">jdbcConnection</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">javaTypeResolver</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"forceBigDecimals"</span> <span class="attr">value</span>=<span class="string">"false"</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">javaTypeResolver</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 生成Model类存放位置 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">javaModelGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"com.alanisia.musicsiteapp.model"</span> <span class="attr">targetProject</span>=<span class="string">"../src/main/java"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"trimStrings"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">javaModelGenerator</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 生成映射文件存放位置 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">sqlMapGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"mapper"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/resources"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">sqlMapGenerator</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 生成Dao类存放位置 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">javaClientGenerator</span> <span class="attr">type</span>=<span class="string">"XMLMAPPER"</span> <span class="attr">targetPackage</span>=<span class="string">"com.alanisia.musicsiteapp.dao"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/java"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">javaClientGenerator</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 生成对应表及类名 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">table</span> <span class="attr">tableName</span>=<span class="string">"%"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">enableCountByExample</span>=<span class="string">"true"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">enableUpdateByExample</span>=<span class="string">"false"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">enableDeleteByExample</span>=<span class="string">"true"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">enableSelectByExample</span>=<span class="string">"true"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">selectByExampleQueryId</span>=<span class="string">"true"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">generatedKey</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">sqlStatement</span>=<span class="string">"MySql"</span> <span class="attr">identity</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 去前缀 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">domainObjectRenamingRule</span> <span class="attr">searchString</span>=<span class="string">"^Ad"</span> <span class="attr">replaceString</span>=<span class="string">""</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">table</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">context</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">generatorConfiguration</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>随后在项目根目录下执行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ mvn mybatis-generator:generate</span><br></pre></td></tr></table></figure>

<p>另外，也可以不在pom.xml导入mybatis-generator依赖，直接将mybatis-generator-1.3.7.jar复制到项目根目录，然后执行以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ java -jar mybatis-generator-1.3.7.jar -configfile mybatis-generator.xml</span><br></pre></td></tr></table></figure>

<p>即可生成代码。若需要重新生成新的代码以覆盖旧的代码，可以加上参数-overwrite。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/mybatis-generator/" data-id="ckpb8zvk5001jdsvl27gig6ld" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mybatis/" rel="tag">mybatis</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/6/">&amp;laquo; 上一页</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><a class="page-number" href="/page/6/">6</a><span class="page-number current">7</span><a class="page-number" href="/page/8/">8</a><a class="page-number" href="/page/9/">9</a><span class="space">&hellip;</span><a class="page-number" href="/page/13/">13</a><a class="extend next" rel="next" href="/page/8/">下一页 &amp;raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/" rel="tag">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/data-structure/" rel="tag">data structure</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/" rel="tag">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/" rel="tag">go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javascript/" rel="tag">javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/json/" rel="tag">json</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/" rel="tag">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/maven/" rel="tag">maven</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/" rel="tag">mybatis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/network/" rel="tag">network</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/" rel="tag">nodejs</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/searching/" rel="tag">searching</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sorting/" rel="tag">sorting</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sublime-text/" rel="tag">sublime text</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/termux/" rel="tag">termux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/theia/" rel="tag">theia</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/typora/" rel="tag">typora</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vala/" rel="tag">vala</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/" rel="tag">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/" rel="tag">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zig/" rel="tag">zig</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/" rel="tag">zookeeper</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/android/" style="font-size: 10px;">android</a> <a href="/tags/data-structure/" style="font-size: 10px;">data structure</a> <a href="/tags/docker/" style="font-size: 10px;">docker</a> <a href="/tags/git/" style="font-size: 15px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/java/" style="font-size: 18.33px;">java</a> <a href="/tags/javascript/" style="font-size: 11.67px;">javascript</a> <a href="/tags/json/" style="font-size: 10px;">json</a> <a href="/tags/linux/" style="font-size: 20px;">linux</a> <a href="/tags/maven/" style="font-size: 10px;">maven</a> <a href="/tags/mybatis/" style="font-size: 10px;">mybatis</a> <a href="/tags/mysql/" style="font-size: 11.67px;">mysql</a> <a href="/tags/network/" style="font-size: 11.67px;">network</a> <a href="/tags/nginx/" style="font-size: 10px;">nginx</a> <a href="/tags/nodejs/" style="font-size: 13.33px;">nodejs</a> <a href="/tags/searching/" style="font-size: 10px;">searching</a> <a href="/tags/sorting/" style="font-size: 16.67px;">sorting</a> <a href="/tags/sublime-text/" style="font-size: 10px;">sublime text</a> <a href="/tags/termux/" style="font-size: 10px;">termux</a> <a href="/tags/theia/" style="font-size: 10px;">theia</a> <a href="/tags/typora/" style="font-size: 10px;">typora</a> <a href="/tags/vala/" style="font-size: 10px;">vala</a> <a href="/tags/vim/" style="font-size: 15px;">vim</a> <a href="/tags/vue/" style="font-size: 11.67px;">vue</a> <a href="/tags/zig/" style="font-size: 10px;">zig</a> <a href="/tags/zookeeper/" style="font-size: 10px;">zookeeper</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/03/">三月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">十一月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/10/">十月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/09/">九月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">八月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/07/">七月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/06/">六月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">五月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">三月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/02/">二月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/java-hashmap/">java.util.HashMap</a>
          </li>
        
          <li>
            <a href="/jvm/">JVM</a>
          </li>
        
          <li>
            <a href="/java-locks/">Java锁</a>
          </li>
        
          <li>
            <a href="/java-references/">Java引用</a>
          </li>
        
          <li>
            <a href="/gitea/">Gitea</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Alanisia<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>